package pe.indra.descarga.servlet;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * Servlet implementation class ObtieneDatosImpreServlet
 */
public class ObtieneDatosImpreServlet extends HttpServlet {
	static Logger logger = Logger.getLogger(ObtieneDatosImpreServlet.class.getName());
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ObtieneDatosImpreServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			logger.info("ejecutando el servlet de descarga");
			logger.info("ejecutando el servlet de descarga");
			ObjectInputStream dataInput = new ObjectInputStream(request.getInputStream());
			String cadenaDatos;			
			cadenaDatos = (String)dataInput.readObject();			
			logger.info(cadenaDatos);
			/*
			InputStream fisForm = new FileInputStream("C:/de/conneg/online/pe/web/formatos/consultasaldos/Form001.frm");						
			byte[] arregloForm = new byte[fisForm.available()];
			fisForm.read(arregloForm);
			
			InputStream fisMedio = new FileInputStream("C:/de/conneg/online/pe/web/formatos/consultasaldos/Medio00.frm");						
			byte[] arregloMedio = new byte[fisMedio.available()];
			fisForm.read(arregloMedio);
			
			ObjectOutputStream dataOutput = new ObjectOutputStream(response.getOutputStream());			
			dataOutput.writeObject(arregloForm);			
			dataOutput.writeObject(arregloMedio);
			
			dataOutput.flush();
			dataInput.close();
			dataOutput.close();*/ 
			String cadenaimpresion = (String)request.getSession().getAttribute("datosimpresion");
			ObjectOutputStream dataOutput = new ObjectOutputStream(response.getOutputStream());			
			dataOutput.writeObject(cadenaimpresion);
			
			dataOutput.flush();
			dataInput.close();
			dataOutput.close();
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
